export default function  constructMenu(data,topId = '0', id='id', pid = 'pid', children = 'children') {
    const getMenuTree = (menu, parent_id) => {
        let result = [];
        let temp = [];
        for(let i = 0, len = menu.length; i< len; i++){
            if(menu[i][pid] === parent_id){
                let item = menu[i];
                temp = getMenuTree(menu, menu[i][id]);
                if(temp.length > 0){
                    item[children] = temp;
                }
                result.push(item);
            }
        }
        return result;
    };
    return getMenuTree(data,topId);
}